package com.ido.otaclient.four;

import android.content.Context;

import com.ido.otaclient.base.BasePreference;
import com.ido.otaclient.env.AppEnv;

/**
 * Copyright (c) 2019 深圳市爱都科技有限公司. All rights reserved.
 *
 * @Author: xyb
 * @CreateDate: 2020-02-28 21:33
 * @description
 */
public class FourToOnePreference extends BasePreference {
    private static final String NAME = "four_preference";

    private static final String TASK_NAME = "taskName";
    private static final String FIREWARE_SPECIAL_NAME = "firewareSpecialName";
    private static final String FIREWARE_SPECIAL_VERSION = "firewareSpecialVersion";
    private static final String FIREWARE_SPECIAL_PATH = "firewareSpecialPath";
    private static final String FIREWARE_NEW_NAME = "firewareNewName";
    private static final String FIREWARE_NEW_VERSION = "firewareNewVersion";
    private static final String FIREWARE_NEW_PATH = "firewareNewPath";
    private static final String BOOTLOADER_NAME = "bootloaderName";
    private static final String BOOTLOADER_VERSION = "bootloaderVersion";
    private static final String BOOTLOADER_PATH = "bootloaderPath";
    private static final String FONT_NAME ="fontName";
    private static final String FONT_NAME_VERSION ="fontVersion";
    private static final String FONT_PATH = "fontPath";
    private static final String DEVICE_ID = "deviceId";
    /**
     * 升级配置
     */
    private FourToOneConfig mUploadConfig;

    private static volatile FourToOnePreference instance;

    private static Context getContext() {
        return AppEnv.instance().getContext();
    }

    public static FourToOnePreference getInstance() {
        if (instance == null) {
            synchronized (FourToOnePreference.class) {
                if (instance == null) {
                    instance = new FourToOnePreference();
                }
            }
        }
        return instance;
    }

    /**
     * 保存配置在本地
     * @param uploadConfig
     */
    public void saveUploadConfig(FourToOneConfig uploadConfig){
        if(uploadConfig == null){
            uploadConfig = new FourToOneConfig();
        }
        saveString(getContext(),NAME,TASK_NAME,uploadConfig.getTaskName());
        saveString(getContext(),NAME,FIREWARE_SPECIAL_NAME,uploadConfig.getFirewareSpecialName());
        saveString(getContext(),NAME,FIREWARE_SPECIAL_VERSION,uploadConfig.getFirewareSpecialVersion());
        saveString(getContext(),NAME,FIREWARE_NEW_NAME,uploadConfig.getFirewareNewName());
        saveString(getContext(),NAME,FIREWARE_NEW_VERSION,uploadConfig.getFirewareNewVersion());
        saveString(getContext(),NAME,BOOTLOADER_NAME,uploadConfig.getBootloaderName());
        saveString(getContext(),NAME,BOOTLOADER_VERSION,uploadConfig.getBootloaderVersion());
        saveString(getContext(),NAME,FONT_NAME,uploadConfig.getFontName());
        saveString(getContext(),NAME,FONT_NAME_VERSION,uploadConfig.getFontVersion());
        saveString(getContext(),NAME,FIREWARE_SPECIAL_PATH,uploadConfig.getFirewareSpecialPath());
        saveString(getContext(),NAME,FIREWARE_NEW_PATH,uploadConfig.getFirewareNewPath());
        saveString(getContext(),NAME,BOOTLOADER_PATH,uploadConfig.getBootloaderPath());
        saveString(getContext(),NAME,FONT_PATH,uploadConfig.getFontPath());
        saveString(getContext(),NAME,DEVICE_ID,uploadConfig.getDeviceId());
        mUploadConfig = uploadConfig;
    }

    /**
     * 从本地取出数据
     * @return
     */
    public FourToOneConfig getUploadConfig(){
        mUploadConfig = new FourToOneConfig();
        mUploadConfig.setTaskName(getString(getContext(),NAME,TASK_NAME));
        mUploadConfig.setFirewareSpecialName(getString(getContext(),NAME,FIREWARE_SPECIAL_NAME));
        mUploadConfig.setFirewareSpecialVersion(getString(getContext(),NAME,FIREWARE_SPECIAL_VERSION));
        mUploadConfig.setFirewareNewName(getString(getContext(),NAME,FIREWARE_NEW_NAME));
        mUploadConfig.setFirewareNewVersion(getString(getContext(),NAME,FIREWARE_NEW_VERSION));
        mUploadConfig.setBootloaderName(getString(getContext(),NAME,BOOTLOADER_NAME));
        mUploadConfig.setBootloaderVersion(getString(getContext(),NAME,BOOTLOADER_VERSION));
        mUploadConfig.setFontName(getString(getContext(),NAME,FONT_NAME));
        mUploadConfig.setFontVersion(getString(getContext(),NAME,FONT_NAME_VERSION));
        mUploadConfig.setFirewareSpecialPath(getString(getContext(),NAME,FIREWARE_SPECIAL_PATH));
        mUploadConfig.setFirewareNewPath(getString(getContext(),NAME,FIREWARE_NEW_PATH));
        mUploadConfig.setBootloaderPath(getString(getContext(),NAME,BOOTLOADER_PATH));
        mUploadConfig.setFontPath(getString(getContext(),NAME,FONT_PATH));
        mUploadConfig.setDeviceId(getString(getContext(),NAME,DEVICE_ID));
        return mUploadConfig;
    }

}
